using System;
using GammaJul.ReSharper.GammaXaml.Highlightings.Xaml;
using JetBrains.Annotations;
using JetBrains.DocumentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Daemon.Impl;
using JetBrains.ReSharper.Psi.Xaml.Tree;

[assembly: RegisterConfigurableSeverity(
	XStaticCanBeUsedHighlighting.SeverityId,
	null,
	HighlightingGroupIds.BestPractice,
	XStaticCanBeUsedHighlighting.Description,
	XStaticCanBeUsedHighlighting.Description,
	Severity.SUGGESTION,
	false)]

namespace GammaJul.ReSharper.GammaXaml.Highlightings.Xaml {

	/// <summary>
	/// An highlighting that indicates that <c>x:Static</c> can be used instead of <c>{RelativeSource}</c>.
	/// </summary>
	[ConfigurableSeverityHighlighting(SeverityId, XamlProjectFileType.Name, OverlapResolve = OverlapResolveKind.NONE)]
	public class XStaticCanBeUsedHighlighting : IHighlightingWithRange {
		internal const string SeverityId = "Xaml.XStaticCanBeUsed";
		internal const string Description = "x:Static can be used to reduce memory usage";

		private readonly IRelativeSourceUsage _relativeSource;

		/// <summary>
		/// Gets the relative source element.
		/// </summary>
		[NotNull]
		public IRelativeSourceUsage RelativeSource {
			get { return _relativeSource; }
		}

		public string ToolTip {
			get { return Description; }
		}

		public string ErrorStripeToolTip {
			get { return Description; }
		}

		public int NavigationOffsetPatch {
			get { return 0; }
		}

		public bool IsValid() {
			return _relativeSource.IsValid();
		}

		public DocumentRange CalculateRange() {
			return _relativeSource.GetHighlightingRange();
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="XStaticCanBeUsedHighlighting"/> class.
		/// </summary>
		/// <param name="relativeSource">The relative source element.</param>
		public XStaticCanBeUsedHighlighting([NotNull] IRelativeSourceUsage relativeSource) {
			if (relativeSource == null)
				throw new ArgumentNullException("relativeSource");
			_relativeSource = relativeSource;
		}
	}

}
